package com.mingyizhudao.app.view.mine;

import java.util.List;
import java.util.Map;

import com.dixiang.framework.BaseActivity;
import com.dixiang.framework.common.QJNetUICallback;
import com.dixiang.framework.common.QjResult;
import com.dixiang.framework.network.Net;
import com.dixiang.framework.widget.LoadingDialog;
import com.google.gson.reflect.TypeToken;
import com.mingyizhudao.app.R;
import com.mingyizhudao.app.utils.CommonUtils;
import com.mingyizhudao.app.utils.Constants;
import com.mingyizhudao.app.view.MYBaseActivity;
import com.mingyizhudao.app.view.mine.adpter.PayListAdapter;
import com.mingyizhudao.app.view.mine.bean.PayListEntity;
import com.mingyizhudao.app.view.mine.bean.PayListEntity.PayOrder;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;


public class PayListActivity extends MYBaseActivity{
	private PayListAdapter payListAdapter;
	private ListView lv_pay;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_pay_list);
		payListAdapter = new PayListAdapter(activity);
		lv_pay = (ListView) findViewById(R.id.lv_pay);
		lv_pay.setAdapter(payListAdapter);
	}
	
	@Override
	public void initHeaderView() {
		
		setTitleViewValue("支付详情");
		setTitleViewValue(0,0,R.color.white);
		setTopViewBg(R.color.actionbar_bg_color);
		initBackView(R.drawable.left_back_white_icon, 0, new OnClickListener() {
			@Override
			public void onClick(View v) {
				finish();
			}
		});
	}
	
	@Override
	protected void onResume() {
		super.onResume();
		getPayDetail();
	}
	
    public void getPayDetail() {
    	LoadingDialog.getInstance(activity).show();
    	String id = getIntent().getStringExtra("id");//orderview
    	String url = Constants.baseURL+"orderlist/"+id+CommonUtils.getTokenParam(activity);
    	getHttpResult(url, Constants.HTTP_INDEX.First, new TypeToken<QjResult<PayListEntity>>() {});
    }
    
    @Override
    public void onSuccess(QjResult result, String flg) {
    	super.onSuccess(result, flg);
    	PayListEntity payListEntity = (PayListEntity) result.getResults();
    	if(payListEntity != null ){
    		setOrderDetail(payListEntity);
    	}else {
			Toast.makeText(activity, "获取数据失败！", Toast.LENGTH_SHORT).show();
		}
    }
    
    @Override
    public void onCompleted(Exception e, String flg) {
    	super.onCompleted(e, flg);
    	LoadingDialog.getInstance(activity).dismiss();
    }
	
    private void setOrderDetail(PayListEntity payListEntity){
    	List<PayOrder> list = payListEntity.getOrders();
    		if(list != null && list.size() > 0){
    			payListAdapter.clear();
    			payListAdapter.addAll(list);
    			payListAdapter.notifyDataSetChanged();
    		}
    		
    		double hasPay = 0;
    		double noPay = 0;
    		
    		if (payListEntity.getHasPay()!=null) {
    			hasPay = Double.parseDouble(payListEntity.getHasPay());
    			((TextView)findViewById(R.id.tv_yizhifu)).setText(payListEntity.getHasPay());
			}
    		if (payListEntity.getNoPay()!=null) {
    			noPay = Double.parseDouble(payListEntity.getNoPay());
        		((TextView)findViewById(R.id.tv_shengyu)).setText(payListEntity.getNoPay());
			}
    	
    		((TextView)findViewById(R.id.tv_total)).setText((hasPay+noPay)+"");
    		
    }
	
}
